<?

include_once "../conn.php";
include_once "../main.php";

$day = date(d);
$month = date(m);
$year = date(Y);
$list_cat = $_POST['cat'];

if(!empty($_GET[JobCategory])){
	$q1 = "select * from job_post where JobCategory like '%$_GET[JobCategory]%'";
	$r1 = mysql_query($q1) or die(mysql_error());
	$s1 = mysql_num_rows($r1);

if($s1 == '0')
{
	echo "<br><br><center><span class=TNA>No results found.</span></center>";
	include_once('../footer.php');
	exit;
}
elseif($s1 == '1')
{
	echo "<br><center><span class=HeaderClass>Your search return one result.</span></center><br><br>";
}
elseif($s1 > '1')
{
	echo "<br><center><span class=HeaderClass>Your search return $s1 results.</span></center><br><br>";
}
	
	$col = "cococo"; 

echo "
<table align=center border=1 bordercolor=993300 cellspacing=0 width=100%>
	<tr>
		<td>
<table align=center width=700 cellspacing=0 cellpadding=2 class=BlackText>
	<tr class=TableHead>
		<td width=90> </td><td width=250 align=center> </td> <td width=70> </td></tr>";

while($ss1 = mysql_fetch_array($r1))
{
	//$ex13 = date('d', mktime(0,0,0, $as[EXmonth] - date(m), $as[EXday] - date(d),  $as[EXyear] - date(Y)));
	
	$time = strtotime($ss1['createdTime']);
	$dateAdd = date("d M Y" ,$time);
	$day = date(d);
	$month = date(m);
	$year = date(Y);

	$EXdate = "$ss1[EXyear]"."-"."$ss1[EXmonth]"."-"."$ss1[EXday]";
	$dnes = "$year"."-"."$month"."-"."$day";

	$qd = "select to_days('$EXdate') - to_days('$dnes')";
	$rqd = mysql_query($qd) or die(mysql_error());
	$ex13 = mysql_fetch_array($rqd);

	 if($col == "cococo")
	    { 
	     $col = "dddddd"; 
	    }
	         	 else
		{ 
		$col = "cococo"; 
		} 
	echo "<tr bgcolor=\"$col\">
		<td>$dateAdd<br><br><br></td>
		<td><a class=BlackLink href=\"JobInfo.php?job_id=$ss1[job_id]\"><font size=3 color=blue>  $ss1[position] </font></a>  ~  <font size=3> $ss1[Company] </font>
		<br>
		$ss1[CompanyState], $ss1[CompanyCountry]
		<br>
		$ss1[short_desc]
		</td>
		<td align=center><b>Expired in $ex13[0] days<br><br><br></b></td>
	  </tr>";
}

echo "</table>";
echo "		</td>
				</tr>
			</table>
			";
echo "<table width=700 align=center><tr>";


	if ($rr2 <= $ByPage && $Start == '0')
	{

	}

	if ( $Start > 0 )
	{
		$nom1 = $Start - $ByPage;
		echo "<td align=left><a class=TNA href=\"JobSearch3.php?sm=$sm&position=$position&CompanyCountry=$CompanyCountry&CompanyState=$CompanyState&JobCategory=$JobCategory&careerlevel=$careerlevel&target_company=$target_company&relocate=$relocate&country=$country&city=$city&kw=$kw&Start=$nom1\">previous</a></td>";
	}

	if ($rr2 > $Start + $ByPage  || ($Start == 0 && $rr2 > $ByPage))
	{
		$nom = $Start + $ByPage;
		echo "<td align=right><a class=TNA href=\"JobSearch3.php?sm=$sm&position=$position&CompanyCountry=$CompanyCountry&CompanyState=$CompanyState&JobCategory=$JobCategory&careerlevel=$careerlevel&target_company=$target_company&relocate=$relocate&country=$country&city=$city&kw=$kw&Start=$nom\">next</a></td>";
	}

echo "</tr></table>";
}


$del = "delete from job_post where EXday = \"$day\" and EXmonth = \"$month\" and EXyear = \"$year\" ";
$rdel = mysql_query($del) or die(mysql_error());

if(!empty($_POST))
{
	extract($_POST);
}

if(!empty($_GET))
{
	extract($_GET);
}

$sch = array(); 
if (!empty($position)) 
{
$sch[] = "position like '%$position%'";
}
if (!empty($country)) 
{
$sch[] = "CompanyCountry = \"$country\" ";
}
if (!empty($state))
{
$sch[] = "CompanyState = '$state' "; 
}
if (!empty($list_cat)) 
{
	foreach ($list_cat AS $key => $value){
$sch[] = "JobCategory like '%$value%' "; 
}
}
if (!empty($JobCategory)) 
{
$sch[] = "JobCategory like '%$JobCategory%' "; 
}
if (!empty($careerlevel))
{
$sch[] = "j_target = '$careerlevel'"; 
}
if (!empty($kw))
{
$sch[] = "short_desc like '%$kw%'"; 
}


if (!$ByPage) $ByPage=25;  
if (!$Start) $Start=0; 

if(empty($sm))
{
	$sm = "and";
}

if($sm == 'or')
{
$qs = "select * from job_post ".(($sch)?"where ".join(" or ", $sch):"")." limit $Start,$ByPage";
$qss = "select * from job_post ".(($sch)?"where ".join(" or ", $sch):"");
}
elseif($sm == 'and')
{
$qs = "select * from job_post ".(($sch)?"where ".join(" and ", $sch):"")." limit $Start,$ByPage";
$qss = "select * from job_post ".(($sch)?"where ".join(" and ", $sch):"");
}
$rqs = mysql_query($qs) or die(mysql_error());
$rqss = mysql_query($qss) or die(mysql_error());

$rr = mysql_num_rows($rqss);

if($rr == '0')
{
	echo "<br><br><center><span class=TNA>No results found.</span></center>";
	include_once('../footer.php');
	exit;
}
elseif($rr == '1')
{
	echo "<br><center><span class=HeaderClass>Your search return one result.</span></center><br><br>";
}
elseif($rr > '1')
{
	echo "<br><center><span class=HeaderClass>Your search return $rr results.</span></center><br><br>";
}

$col = "cococo"; 

echo "
<table align=center border=1 bordercolor=993300 cellspacing=0 width=700>
	<tr>
		<td>
<table align=center width=700 cellspacing=0 cellpadding=2 class=BlackText>
	<tr class=TableHead>
		<td width=90> </td><td width=250 align=center> </td> <td width=70> </td></tr>";

while($as = mysql_fetch_array($rqs))
{
	//$ex13 = date('d', mktime(0,0,0, $as[EXmonth] - date(m), $as[EXday] - date(d),  $as[EXyear] - date(Y)));
	
	$time = strtotime($as['createdTime']);
	$dateAdd = date("d M Y" ,$time);
	$day = date(d);
	$month = date(m);
	$year = date(Y);

	$EXdate = "$as[EXyear]"."-"."$as[EXmonth]"."-"."$as[EXday]";
	$dnes = "$year"."-"."$month"."-"."$day";

	$qd = "select to_days('$EXdate') - to_days('$dnes')";
	$rqd = mysql_query($qd) or die(mysql_error());
	$ex13 = mysql_fetch_array($rqd);

	 if($col == "cococo")
	    { 
	     $col = "dddddd"; 
	    }
	         	 else
		{ 
		$col = "cococo"; 
		} 
	echo "<tr bgcolor=\"$col\">
		<td>$dateAdd<br><br><br></td>
		<td><a class=BlackLink href=\"JobInfo.php?job_id=$as[job_id]\"><font size=3 color=blue>  $as[position] </font></a>  ~  <font size=3> $as[Company] </font>
		<br>
		$as[CompanyState], $as[CompanyCountry]
		<br>
		$as[short_desc]
		</td>
		<td align=center><b>Expired in $ex13[0] days<br><br><br></b></td>
	  </tr>";
}


if($sm == 'or')
{
$qs2 = "select * from job_post ".(($sch)?"where ".join(" or ", $sch):"");
}
elseif($sm == 'and')
{
$qs2 = "select * from job_post ".(($sch)?"where ".join(" and ", $sch):"");
}
$rqs2 = mysql_query($qs2) or die(mysql_error());
$rr2 = mysql_num_rows($rqs2);

echo "</table>";
echo "		</td>
				</tr>
			</table>
			";
echo "<table width=700 align=center><tr>";


	if ($rr2 <= $ByPage && $Start == '0')
	{

	}

	if ( $Start > 0 )
	{
		$nom1 = $Start - $ByPage;
		echo "<td align=left><a class=TNA href=\"JobSearch3.php?sm=$sm&position=$position&CompanyCountry=$CompanyCountry&CompanyState=$CompanyState&JobCategory=$JobCategory&careerlevel=$careerlevel&target_company=$target_company&relocate=$relocate&country=$country&city=$city&kw=$kw&Start=$nom1\">previous</a></td>";
	}

	if ($rr2 > $Start + $ByPage  || ($Start == 0 && $rr2 > $ByPage))
	{
		$nom = $Start + $ByPage;
		echo "<td align=right><a class=TNA href=\"JobSearch3.php?sm=$sm&position=$position&CompanyCountry=$CompanyCountry&CompanyState=$CompanyState&JobCategory=$JobCategory&careerlevel=$careerlevel&target_company=$target_company&relocate=$relocate&country=$country&city=$city&kw=$kw&Start=$nom\">next</a></td>";
	}

echo "</tr></table>";


?>
<? include_once('../footer.php'); ?>